package week04.day02;

import java.util.Random;
import java.util.Scanner;

/**
 * 猜数字游戏
 * 先随机生成一个1-100之间的随机整数，然后进行猜测
 * 输出：太大了，太小了，猜对了
 */
public class do_while循环练习 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int num = new Random().nextInt(100) + 1;
        int cishu = 0;
        do {
            System.out.println("请输入一个1-100之间的整数");
            int num1 = scanner.nextInt();
            if (num1 > num) {
                System.out.println("太大了！");
            }else if (num1<num){
                System.out.println("太小了！");
            }else if (num1==num){
                System.out.println("猜对了！");
                break;//结束循环
            }
            cishu++;
        }while (cishu<9);
        System.out.println("您使用了"+cishu+"次机会猜对！");
    }
}

